﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;

namespace WebsiteAdmin.Salomon.ProInfo
{
    public partial class ProList : System.Web.UI.Page
    {

        public int countPage;
        public int countRow;
        public int pageSize = Global.PageSize;
        public int pageIndex = 1;
        public string whereStr = "WHERE [TProduct].[Valid] = 1";
        public string urlStr = "";
        
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Request["page"] != null && Request["page"] != "")
                    pageIndex = Convert.ToInt32(Request["page"].ToString());

                Bll.DataGroup dtProduct = Bll.Product.MULTIPLE(Global.ConSalomon, pageSize, pageIndex, whereStr);

                if (dtProduct.DT.Rows.Count > 0)
                {
                    RP_Product.DataSource = dtProduct.DT.DefaultView;
                    RP_Product.DataBind();
                }


                Pagination.ProcessPageToHtml(pageSize, pageIndex, urlStr, dtProduct.Row, dtProduct.Page);
                dtProduct.Dispose();
            }
            else
            {
                Response.Redirect("/Trace.aspx?Err=1");
            }
        }

        protected void RP_Product_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            // Execute the following logic for Items and Alternating Items.
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                // 找到分类Repeater关联的数据项
                DataRowView rowv = (DataRowView)e.Item.DataItem;

                Label lblCatName = ((Label)e.Item.FindControl("CatName"));
                lblCatName.Text = rowv["CatName"].ToString();
                if (Convert.ToInt32(rowv["CatValid"]) == 0)
                {                    
                    lblCatName.CssClass = "del";
                }

                Label lblSerName = ((Label)e.Item.FindControl("SerName"));
                lblSerName.Text = rowv["SerName"].ToString();
                if (Convert.ToInt32(rowv["CatValid"]) == 0 || Convert.ToInt32(rowv["SerValid"]) == 0)
                {
                    lblSerName.CssClass = "del";
                }

                Image thumbURL = ((Image)e.Item.FindControl("ThumbURL"));

                if (rowv["ThumbURL"].ToString().Trim().Length > 0)
                {
                    thumbURL.ImageUrl = rowv["ThumbURL"].ToString();
                }
                else
                {
                    thumbURL.ImageUrl = "/Images/view.png";
                }

            }
        }
    }
}
